<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="单位名称" prop="companyName">
      <el-input v-model="dataForm.companyName" placeholder="单位名称"></el-input>
    </el-form-item>
    <el-form-item label="法人姓名" prop="corName">
      <el-input v-model="dataForm.corName" placeholder="法人姓名"></el-input>
    </el-form-item>
    <el-form-item label="联系电话" prop="telphone">
      <el-input v-model="dataForm.telphone" placeholder="联系电话"></el-input>
    </el-form-item>
    <el-form-item label="补贴人数" prop="subsidyNumbers">
      <el-input v-model="dataForm.subsidyNumbers" placeholder="补贴人数"></el-input>
    </el-form-item>
    <el-form-item label="补贴金额" prop="subsidy">
      <el-input v-model="dataForm.subsidy" placeholder="补贴金额"></el-input>
    </el-form-item>
    <el-form-item label="核查单位" prop="inspect">
      <el-input v-model="dataForm.inspect" placeholder="核查单位"></el-input>
    </el-form-item>
    <el-form-item label="纸质材料" prop="paper">
      <el-input v-model="dataForm.paper" placeholder="纸质材料"></el-input>
    </el-form-item>
    <el-form-item label="图片材料" prop="image">
      <el-input v-model="dataForm.image" placeholder="图片材料"></el-input>
    </el-form-item>
    <el-form-item label="影像材料" prop="vedio">
      <el-input v-model="dataForm.vedio" placeholder="影像材料"></el-input>
    </el-form-item>
    <el-form-item label="核查结果" prop="result">
      <el-input v-model="dataForm.result" placeholder="核查结果"></el-input>
    </el-form-item>
    <el-form-item label="不合格原因" prop="reason">
      <el-input v-model="dataForm.reason" placeholder="不合格原因"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="editTime">
      <el-input v-model="dataForm.editTime" placeholder="修改时间"></el-input>
    </el-form-item>
    <el-form-item label="纸质材料地址" prop="paperUrl">
      <el-input v-model="dataForm.paperUrl" placeholder="纸质材料地址"></el-input>
    </el-form-item>
    <el-form-item label="图片材料地址" prop="imageUrl">
      <el-input v-model="dataForm.imageUrl" placeholder="图片材料地址"></el-input>
    </el-form-item>
    <el-form-item label="影像材料地址" prop="vedioUrl">
      <el-input v-model="dataForm.vedioUrl" placeholder="影像材料地址"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          companyName: '',
          corName: '',
          telphone: '',
          subsidyNumbers: '',
          subsidy: '',
          inspect: '',
          paper: '',
          image: '',
          vedio: '',
          result: '',
          reason: '',
          createTime: '',
          editTime: '',
          paperUrl: '',
          imageUrl: '',
          vedioUrl: ''
        },
        dataRule: {
          companyName: [
            { required: true, message: '单位名称不能为空', trigger: 'blur' }
          ],
          corName: [
            { required: true, message: '法人姓名不能为空', trigger: 'blur' }
          ],
          telphone: [
            { required: true, message: '联系电话不能为空', trigger: 'blur' }
          ],
          subsidyNumbers: [
            { required: true, message: '补贴人数不能为空', trigger: 'blur' }
          ],
          subsidy: [
            { required: true, message: '补贴金额不能为空', trigger: 'blur' }
          ],
          inspect: [
            { required: true, message: '核查单位不能为空', trigger: 'blur' }
          ],
          paper: [
            { required: true, message: '纸质材料不能为空', trigger: 'blur' }
          ],
          image: [
            { required: true, message: '图片材料不能为空', trigger: 'blur' }
          ],
          vedio: [
            { required: true, message: '影像材料不能为空', trigger: 'blur' }
          ],
          result: [
            { required: true, message: '核查结果不能为空', trigger: 'blur' }
          ],
          reason: [
            { required: true, message: '不合格原因不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          editTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          paperUrl: [
            { required: true, message: '纸质材料地址不能为空', trigger: 'blur' }
          ],
          imageUrl: [
            { required: true, message: '图片材料地址不能为空', trigger: 'blur' }
          ],
          vedioUrl: [
            { required: true, message: '影像材料地址不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/generator/threepartresult/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.companyName = data.threePartResult.companyName
                this.dataForm.corName = data.threePartResult.corName
                this.dataForm.telphone = data.threePartResult.telphone
                this.dataForm.subsidyNumbers = data.threePartResult.subsidyNumbers
                this.dataForm.subsidy = data.threePartResult.subsidy
                this.dataForm.inspect = data.threePartResult.inspect
                this.dataForm.paper = data.threePartResult.paper
                this.dataForm.image = data.threePartResult.image
                this.dataForm.vedio = data.threePartResult.vedio
                this.dataForm.result = data.threePartResult.result
                this.dataForm.reason = data.threePartResult.reason
                this.dataForm.createTime = data.threePartResult.createTime
                this.dataForm.editTime = data.threePartResult.editTime
                this.dataForm.paperUrl = data.threePartResult.paperUrl
                this.dataForm.imageUrl = data.threePartResult.imageUrl
                this.dataForm.vedioUrl = data.threePartResult.vedioUrl
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/generator/threepartresult/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'companyName': this.dataForm.companyName,
                'corName': this.dataForm.corName,
                'telphone': this.dataForm.telphone,
                'subsidyNumbers': this.dataForm.subsidyNumbers,
                'subsidy': this.dataForm.subsidy,
                'inspect': this.dataForm.inspect,
                'paper': this.dataForm.paper,
                'image': this.dataForm.image,
                'vedio': this.dataForm.vedio,
                'result': this.dataForm.result,
                'reason': this.dataForm.reason,
                'createTime': this.dataForm.createTime,
                'editTime': this.dataForm.editTime,
                'paperUrl': this.dataForm.paperUrl,
                'imageUrl': this.dataForm.imageUrl,
                'vedioUrl': this.dataForm.vedioUrl
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
